<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="8" :xs="24">
<!--        <div class="head-container">
          <el-input v-model="robot_name" placeholder="请输入机器人名称" clearable size="small" prefix-icon="el-icon-search"
                    style="margin-bottom: 20px" @change="getRobotName($event)" />
        </div>
        <div class="head-container" style="border:1px solid #0a328a;">
          &lt;!&ndash;机器人列表&ndash;&gt;
          <el-table v-loading="false" :data="robotList" @row-click="getSelectdata"
                    @selection-change="handleSelectionChange" :cell-style="{ borderColor: 'rgb(1 5 43)' }"
                    :header-cell-style="{ borderColor: 'rgb(1 5 43)' }">
            <el-table-column label="机器人编号" align="center" prop="robot_num" />
            <el-table-column label="机器人名称" align="center" prop="robot_name" width="90px" />
          </el-table>
        </div>-->
        <!-- 巡检点采集趋势图-->
        <div style="color: #469cc5;font-weight: 600;letter-spacing: 4px;text-align: center;font-size:16px;">
          巡检点气体/温湿度最大值趋势图
        </div>
        <div class="head-container" style="border:1px solid #0a328a;margin-top: 20px">
          <div id="container"  ref="chinaMapChart" style="height: 540px"></div>
        </div>
      </el-col>
      <div style="color: #469cc5;font-weight: 600;letter-spacing: 4px;text-align: center;font-size: 16px;">
        巡检点气体/温湿度数据采集列表
      </div>
    <!-- 查询条件区域-->
    <el-col :span="16" :xs="24">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="任务名称" prop="task_name">
        <el-input  style="width: 150px"
          v-model="queryParams.task_name"
          placeholder="请输入任务名称"
          clearable
          @keyup.enter.native="handleQuery"
          size="small"
        />
      </el-form-item>
      <el-form-item label="机器人名称" prop="robot_name">
        <el-input  style="width: 150px"
          v-model="queryParams.robot_name"
          placeholder="请输入机器人名称"
          clearable
          @keyup.enter.native="handleQuery"
          size="small"
        />
      </el-form-item>
      <el-form-item label="参数类型" prop="param_name">
        <el-select style="width: 150px" size="small" v-model="queryParams.param_name" placeholder="请选参数类型">
          <el-option
              v-for="item in alarmParamList"
              :key="item.id"
              :label="item.param_name"
              :value="item.param_name"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="采集时间">
        <el-date-picker
            v-model="queryParams.create_times"
            style="width: 212px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
     <!--增删改查按钮区域-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['robot:patroltaskresult:remove']"
        >删除</el-button>
      </el-col>
     <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
     <!-- 数据列表区域-->
    <el-table v-loading="loading" :data="patroltaskListHis" @selection-change="handleSelectionChange" :cell-style="{borderColor:'rgb(1 5 43)'}" :header-cell-style="{borderColor: 'rgb(1 5 43)'}" >
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column
        label="任务编码"
        align="center"
        prop="task_num"
        :show-overflow-tooltip="true"
      />-->
      <el-table-column label="机器人名称" align="center" prop="robot_name" />
      <el-table-column label="任务名称" align="center" prop="task_name"/>
      <el-table-column label="巡检点" align="center" prop="position_num"/>
      <el-table-column label="采集来源" align="center" prop="resc"/>
      <el-table-column label="采集值" align="center" prop="vals"/>
      <el-table-column label="采集时间" align="center" prop="creater_time_str" width="180"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['robot:patroltaskresult:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--列表分页区域-->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList" style="background:rgb(1 5 43);"
    />
    </el-col>
    </el-row>
  </div>
</template>
<script>
import {delPatrolTaskHIS, listPatrolTaskHIS, listPatrolTaskHIScharts} from "@/api/robot/patroltask/patroltask";
import {listonPageRobotConfig} from "@/api/robot/robotconfig/robotconfig";
import "@/assets/styles/robt-bg.css";
import {listParamType} from "@/api/robot/paramtype/paramtype";
import * as echarts from 'echarts';
import $ from 'jquery';
let myChart = null;
export default {
  name: "DiagramData",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //机器人表格数据
      robotList: [],
      // 巡检任务历史表格数据
      patroltaskListHis: [],
      //查询条件区域--初始化参数列表
      alarmParamList:[],
      checkList: [],
      // 弹出层标题
      title: "",
      robot_name: undefined,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 8,
        task_name: undefined,
        robot_name: undefined,
        param_name: undefined,
        create_times: [/*this.dealWithTime(new Date()), this.dealWithTime(new Date())*/],
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getrobotList();//机器人列表
    this.getParamList();//查询条件区域---------初始化下拉选择参数列表
  },
  beforeDestroy() {
    if(myChart != null){myChart.clear();myChart = null;}
  },
  methods: {
    getParamList() {
      listParamType(this.queryParams).then(response => {
        this.alarmParamList = response.rows;
      });
    },
    /** 根据输入框机器人名称，查询机器人列表 */
    getRobotName(robot_name) {
      this.queryParams.robot_name = robot_name;
      this.getrobotList();
    },
    /** 查询机器人列表 */
    getrobotList() {
      this.loading = false;
      listonPageRobotConfig(this.queryParams).then(response => {
        this.robotList = response.rows;
        this.camera_type1 = this.robotList[0].camera_type
      });
    },
    //获取当前选中机器人数据
    getSelectdata(row) {
      this.queryParams.robot_config_id = row.id;
      this.getList();
    },
    /** 查询巡检任务列表、曲线图表 */
    getList() {
      this.loading = true;
      listPatrolTaskHIS(this.queryParams).then(response => {
        this.patroltaskListHis = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      listPatrolTaskHIScharts(this.queryParams).then(response => {
        let xjds = [];//巡检点
        let yqs = [];//氧气
        let aqs = [];//氨气
        let lhqs = [];//硫化氢
        let jws = [];//甲烷
        let wds = [];//现场温度
        let sds = [];//现场湿度
        if(typeof response.rows !='undefined') {
          let xjdqst = response.rows;//巡检点采集趋势图
          let size_xjdqst = xjdqst.length;
          for(let x=0;x < size_xjdqst;x++) {
            xjds[x] = xjdqst[x].position_num;//巡检点
            yqs[x] = xjdqst[x].yq;//氧气
            aqs[x] = xjdqst[x].aq;//氨气
            lhqs[x] = xjdqst[x].lhq;//硫化氢
            jws[x] = xjdqst[x].jw;//甲烷
            wds[x] = xjdqst[x].xcwd;//现场温度
            sds[x] = xjdqst[x].xcsd;//现场湿度
          }
          if(size_xjdqst > 0 ) {
            this.xjdqst(xjds, yqs, aqs, lhqs, jws, wds, sds);//巡检点采集趋势图
          } else {
            this.xjdqst([0], [0], [0], [0], [0], [0], [0]);//巡检点采集趋势图
          }
        } else {
          if(myChart != null) myChart.dispose()//销毁echarts
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        task_name: undefined,
        robot_name:undefined,
        robot_config_id :undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.robot_name = undefined;
      this.queryParams.task_name = undefined;
      this.queryParams.robot_config_id = undefined;
      this.queryParams.create_times = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.task_names = selection.map(item => item.task_name)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    // 多选框选中点位数据
    handleSelectionChangePatrolPoint(selection) {
      this.point_ids = selection.map(item => item.id)
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      const task_names =row.task_name || this.task_names
      this.$modal.confirm('是否确认删除任务名称为"' + task_names + '"的数据项？').then(function() {
        return delPatrolTaskHIS(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    // 取消按钮
    cancel1() {
      this.open1 = false;
      this.reset();
    },
   /* 巡检点采集趋势图*/
    xjdqst(xjds, yqs, aqs, lhqs, jws, wds, sds){
      setTimeout(() => {
        myChart = echarts.init(this.$refs.chinaMapChart)
        let option;
        option = {
          title: {
            text: ''
          },
          tooltip: {
            trigger: 'axis'
          },
          color: ['#02678c', '#2b2ecb', '#cc8a0e', '#560caf', '#0e9f54', '#3b7fd5'],
          legend: {
            data: ['甲烷', '氨气', '氧气', '硫化氢', '现场湿度', '现场温度'],
            textStyle: {
              color: "#a4a5a6"
            }
          },
          grid: {
            left: '3%',
            right: '8%',
            bottom: '3%',
            containLabel: true
          },
          toolbox: {
            feature: {
              saveAsImage: {}
            }
          },
          xAxis: {
            axisLine: {
              show: true, // 不显示坐标轴线
              lineStyle: {
                color: '#0d409f', //x轴的颜色
              }
            },//横坐标值颜色
            axisLabel: {
              show: true,
              textStyle: {
                color: '#7287ab'
              }
            },
            splitLine: {
              show: false // 不显示网格线
            },
            type: 'category',
            boundaryGap: false,
            data: xjds,
            markPoint: {
              data: [
                { type: 'max', name: 'Max' },
                { type: 'min', name: 'Min' }
              ]
            },
            markLine: {
              data: [{ type: 'average', name: 'Avg' }]
            }
          },
          yAxis: {
            axisTick: {
              show: true,  //刻度线
            },
            axisLine: {
              show: true, // 显示坐标轴线
              lineStyle: {
                color: '#0d409f', //x轴的颜色
              }
            },
            splitLine: {
              show: false // 不显示网格线
            },
            type: 'value'
          },
          series: [
            {
              symbol:'circle',//空心点改为实心点
              symbolSize:6,
              smooth: true,
              name: '甲烷',
              type: 'line',
              stack: 'Total',
              data: jws,
              markPoint: {
                data: [
                  { type: 'max', name: 'Max' },
                  { type: 'min', name: 'Min' }
                ]
              },
              markLine: {
                data: [{ type: 'average', name: 'Avg' }]
              }
            },
            {
              symbol:'circle',//空心点改为实心点
              symbolSize:6,
              smooth: true,
              name: '氨气',
              type: 'line',
              stack: 'Total',
              data: aqs,
              markPoint: {
                data: [
                  { type: 'max', name: 'Max' },
                  { type: 'min', name: 'Min' }
                ]
              },
              markLine: {
                data: [{ type: 'average', name: 'Avg' }]
              }
            },
            {
              symbol:'circle',//空心点改为实心点
              symbolSize:6,
              smooth: true,
              name: '氧气',
              type: 'line',
              stack: 'Total',
              data: yqs,
              markPoint: {
                data: [
                  { type: 'max', name: 'Max' },
                  { type: 'min', name: 'Min' }
                ]
              },
              markLine: {
                data: [{ type: 'average', name: 'Avg' }]
              }
            },
            {
              symbol:'circle',//空心点改为实心点
              symbolSize:6,
              smooth: true,
              name: '硫化氢',
              type: 'line',
              stack: 'Total',
              data: lhqs,
              markPoint: {
                data: [
                  { type: 'max', name: 'Max' },
                  { type: 'min', name: 'Min' }
                ]
              },
              markLine: {
                data: [{ type: 'average', name: 'Avg' }]
              }
            },
            {
              symbol:'circle',//空心点改为实心点
              symbolSize:6,
              smooth: true,
              name: '现场湿度',
              type: 'line',
              stack: 'Total',
              data: sds,
              markPoint: {
                data: [
                  { type: 'max', name: 'Max' },
                  { type: 'min', name: 'Min' }
                ]
              },
              markLine: {
                data: [{ type: 'average', name: 'Avg' }]
              }
            },
            {
              symbol:'circle',//空心点改为实心点
              symbolSize:6,
              smooth: true,
              name: '现场温度',
              type: 'line',
              stack: 'Total',
              data:wds,
              markPoint: {
                data: [
                  { type: 'max', name: 'Max' },
                  { type: 'min', name: 'Min' }
                ]
              },
              markLine: {
                data: [{ type: 'average', name: 'Avg' }]
              }
            }
          ], dataZoom: [
          {
            fillerColor:'#0e2e79',
            borderColor:'#1c44a2',
            height:20,
            bottom:40,
            type: 'inside',
            startValue: 0,
            endValue: 6
          },
          {
            fillerColor:'#0e2e79',
            borderColor:'#1c44a2',
            height:20,
            bottom:40,
            startValue: 0,
            endValue: 6
          }
        ]
        };
        if (option && typeof option === 'object') {
          myChart.setOption(option);
        }
        window.addEventListener("resize", () => {
          if(myChart!=null)myChart.resize();
        });
      }  , 1);
    }
  }
};
</script>
<style rel="stylesheet/scss" lang="scss">
/**列表添加垂直隐藏滚动条**/
.tabled{
height: 550px;
overflow: hidden;
overflow-y: scroll;
}
.tabled::-webkit-scrollbar {
width: 0 !important;
height: 0 !important;
}
</style>
